<?php
namespace App\Admin\Extensions;
use Encore\Admin\Admin;

class ChangeState
{
    protected $id = '';
    protected $collector_id;
    protected $orderid;

    public function __construct($collector_id, $orderid)
    {
        $this->collector_id = $collector_id;
        $this->orderid = $orderid;
    }

    protected function script()
    {
        return <<<SCRIPT
layui.use('layer', function(){
        var layer = layui.layer;
        $('.cuishou').click(function () {
           var that = this;
           layer.confirm('确定领取催收?', {icon: 3, title:'提示'}, function(index){
               var orderid = $(that).attr('data-orderid');
               $.ajax({
                    url: '/admin/cuishou?orderid='+orderid,
                    type: 'get',
                   success: function (res) {
                       if(res.code) {
                           layer.msg(res.text)
                           layer.close(index);
                           return;
                       }
                       layer.msg(res.text);
                       $(that).prop('disabled', true);
                       layer.close(index);
                   }
               })
           });
       });
});

SCRIPT;
    }

    protected function render()
    {
        Admin::script($this->script());
        return "&nbsp;<a href='javascript:void(0);'><button  data-collector='{$this->collector_id}' data-orderid='{$this->orderid}'  class='cuishou layui-btn btn-primary layui-btn-xs'>领取</button></a>";
    }

    public function __toString()
    {
        return $this->render();
    }
}
